package com.study.hisapi.controller;

import com.study.hisapi.domain.bo.UserInfoBo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author LiXiao
 * @date 2024/4/10
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {
    @PostMapping("/test")
    public void user(@Validated @RequestBody UserInfoBo infoBo, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            System.out.println("有异常信息");
            for (ObjectError error : bindingResult.getAllErrors()) {
                System.out.println("error.getDefaultMessage() = " + error.getDefaultMessage());
            }
        }
        log.info(infoBo.toString());
    }

    @PostMapping("/test2")
    public void user2(UserInfoBo infoBo) {
        log.info(infoBo.toString());
        UserInfoBo userInfoBo = new UserInfoBo();
        userInfoBo.setOrgId("2");
        userInfoBo.setUserId("2");
        log.info(userInfoBo.toString());

    }
}
